# -*- coding: utf-8 -*-
# @Time    : 2021/12/14 10:08
# @Author  : TangDagui
# @Email   : 3297364807@qq.com
# @File    : __init__.py.py
# @Software: PyCharm
import xlrd

data = xlrd.open_workbook(r"C:\Users\Administrator\PycharmProjects\pythonTask\mrTang\day2021-12-14\超市营业额2.xls")
table = data.sheets()[0]

# 创建一个空列表，存储Excel的数据
tables = []
# 建立一个标题 用于字典读取
columnTitle = ["JobNumber", "name", "date", "TimePeriod", "tradeMoney", "counter"]


# 将excel表格内容导入到tables列表中
def import_excel(excel):
    for rown in range(excel.nrows):
        array = {'JobNumber': '', 'name': '', 'date': '', 'TimePeriod': '', 'tradeMoney': '', 'counter': ''}
        array['JobNumber'] = table.cell_value(rown, 0)
        array['name'] = table.cell_value(rown, 1)
        array['date'] = table.cell_value(rown, 2)
        array['TimePeriod'] = table.cell_value(rown, 3)
        array['tradeMoney'] = table.cell_value(rown, 4)
        array['counter'] = table.cell_value(rown, 5)
        tables.append(array)


# 输出下标start-end的行数据
def subscriptStartToEnd(start, end):
    mData = [0] * len(tables[start:end])
    for i in range(len(tables[start:end])):
        mData[i] = tables[start:end][i]
        pass
    return mData
    pass


# 输出指定行列的值
def subscriptRanks(row, column):
    if len(row) == len(column):
        for i in range(len(row)):
            obtainRow = row[i][0]  # 获取行
            dictData = obtainRow[columnTitle[column[i]]]  # 对行进行字典读取
            print("{0}:{1}".format([columnTitle[column[i]]][0], dictData))
    else:
        print("行列个数不一样")


if __name__ == '__main__':
    # 将excel表格的内容导入到列表中
    import_excel(table)
    print("----第一题-----")
    # 1.下标在[5,10]区间的行
    print(subscriptStartToEnd(5, 10))
    print("----第二题-----")
    # 2.下标为5的行
    print(subscriptStartToEnd(5, 6))
    print("----第三题-----")
    subscriptRanks([subscriptStartToEnd(3, 4), subscriptStartToEnd(5, 6), subscriptStartToEnd(10, 11)],
                   [0, 1, 4])  # 输出指定行列的值
# 3.行下标为[3,5,10],列下标为[0,1,4]的数据
